#!/usr/bin/env python3
import sys
assert sys.version_info[0] >= 3, "Python 3 required."

# Lizard
# Copyright Brad Smith 2018
# http://lizardnes.com

import datetime
now_string = datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y")

import os
OUTPUT_DIR = os.path.join("assets","export")
if not os.path.exists(OUTPUT_DIR):
    os.makedirs(OUTPUT_DIR)

import PIL.Image
image = PIL.Image.open("lizard_icon.png")
d = []
image.convert("RGBA")
(width,height) = image.size
for y in range(0,height):
    for x in range(0,width):
        (r,g,b,a) = image.getpixel((x,y))
        p = (a << 24) | (r << 16) | (g << 8) | b
        d.append(p)

s = "#pragma once\n"
s += "// automatically generated by build_icon_h.py\n"
s += "//" + now_string + "\n"
s += "\n"
s += "const Uint32 icon[%d] = { // (%d x %d ARGB)\n" % (len(d),width,height)
rc = 0
for b in d:
    if rc == 0:
        s += "\t"
    s += "0x%08X," % b
    rc += 1
    if (rc >= width):
        s += "\n"
        rc = 0
if (rc > 0):
    s += "\n"
s += "};\n"
s += "\n"
s += "// end of file\n"
f = open(os.path.join(OUTPUT_DIR,"icon.h"),"wt")
f.write(s)
f.close()
print ("Done.")
